package com.hongkzh.www.shop.service;

import com.hongkzh.www.adv.service.BaseService;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;

import java.util.List;

public class CategoryService extends BaseService {


    public List<Record> getCategoryList() {
        SqlPara sqlPara=Db.getSqlPara("shop.getCategoryList");
        List<Record> records=Db.find(sqlPara);
        for (Record r:records
             ) {
            doFilePath(r);
        }
        return records;
    }

    public Record getCategoryById(String pid) {
        SqlPara sqlPara=Db.getSqlPara("shop.getCategoryById",pid);
        Record r=Db.findFirst(sqlPara);
        doFilePath(r);
        return r;
    }

    public List<Record> getSubCategoryList(String pid) {
        SqlPara sqlPara=Db.getSqlPara("shop.getSubCategoryList",pid);
        List<Record> records=Db.find(sqlPara);
        for (Record r:records
                ) {
            doFilePath(r);
        }
        return records;
    }

    /**
     * 主页轮播图
     * @return
     */
    public List<Record> getCarouselList(int i) {
        List<Record> records=Db.find(Db.getSqlPara("shop.getCarouselList",i));
        for (Record r:records
                ) {
            doFilePath(r);
        }
        return records.size()>0?records:null;
    }

}
